import time;
import logging;

STR_TYPE = type('');

class BlogPosting:
    def __init__(self):
        self.title = '';
        self.date = 0;
        self.url = '';
        self.description = '';
        self.commentUrl = '';
        self.comments = [];
        
        
    def __str__(self):
        text = 'TITLE:\t' + self.title + '\n';
        try:
            text += 'URL:\t' + self.url + '\n';
        except:
            import sys;
            print self.url;
            sys.exit(-1);
        dateFormat = '%a, %d %b %Y %H:%M:%S %Z';
        text += 'DATE:\t' + time.strftime(dateFormat, time.gmtime(self.date)) + '\n';
        try:
            text += 'DES:\t' + self.description + '\n';
        except:
            return '';
        if self.commentUrl:
            text += 'COURL:\t' + self.commentUrl + '\n';
        for comment in self.comments:
            text += 'COMM:\n' + comment.__str__() + '\n';
        text += '-' * 100;
        if(type(text) <> STR_TYPE):
            text = unicode(text).encode('utf-8');
        return text;
    
    def toTRECFormat(self):
        text = '<DOC>\n';
        text += '<DOCNO>' + self.url + '</DOCNO>\n';
        dateFormat = '%Y-%m-%d-%H-%M';
        text += '<DATE>' + time.strftime(dateFormat, time.gmtime(self.date)) + '</DATE>\n';
        text += '<TITLE>' + self.title + '</TITLE>\n';
        text += '<TEXT>\n' + self.description + '\n</TEXT>\n';
        text += '</DOC>\n';
        return text;
        
        
def blogEntryDateCmp(entry1, entry2):
    result = entry2.date - entry1.date;
    if result > 0:
        return 1;
    elif result < 0:
        return -1;
    return 0;  

class BlogProfile:
    def __init__(self):
        self.title = '';
        self.author = '';
        self.userid = '';
        self.url = '';
        self.interests = '';
        self.age = -1;
        self.gender = '';
        self.occupation = '';
        self.homeCountry = '';
        self.homeCity = '';
        self.realName = '';
        self.placesLived = '';
        self.maritalStatus = '';
        self.bio = '';
        self.type = '';
        
    def __str__(self):
        text = "URL: " + self.url + '\n';
        text += 'AUTHOR: ' + self.author + '\n';
        if self.title:
            text += 'TITLE: ' + self.title + '\n';
        if self.userid:
            text += 'ID: ' + self.userid + '\n';
        if self.type:
            text += 'TYPE: ' + self.type + '\n';
        if self.interests:
            text += 'INTERESTS: ' + self.interests + '\n';
        if self.age > 0:
            text += 'AGE: ' + str(self.age) + '\n';
        if self.gender:
            text += 'GENDER: ' + self.gender + '\n';
        if self.occupation:
            text += 'OCCUPATION: ' + self.occupation + '\n';
        if self.homeCountry:
            text += 'HOMECOUNTRY: ' + self.homeCountry + '\n';
        if self.homeCity:
            text += 'HOMECITY: ' + self.homeCity + '\n';
        if self.realName:
            text += 'REALNAME: ' + self.realName + '\n';
        if self.placesLived:
            text += 'PLACELIVED: ' + self.placesLived + '\n';
        if self.maritalStatus:
            text += 'MARITALSTATUS: ' + self.maritalStatus + '\n';
        if self.bio:
            text += 'BIO: ' + self.bio + '\n';
        text += '-' * 100;
        if(type(text) <> STR_TYPE):
            text = unicode(text).encode('utf-8', 'ignore');
        return text;
                    

class BlogUserProfile(BlogProfile):
    def __init__(self):
        BlogProfile.__init__(self);
        self.friendships = [];

class BlogCommunityProfile(BlogProfile):
    def __init__(self):
        BlogProfile.__init__(self);
        self.communityships = [];        

class BlogComment:
    def __init__(self):
        self.authorName = '';
        self.authorEmail = '';
        self.authorId = '';
        self.authorUrl = '';
        self.content = '';
        self.date = '';
    def __str__(self):
        text = 'AUTHOR NAME: ' + self.authorName + '\n';
        text += 'AUTHOR MAIL: ' + self.authorEmail + '\n';
        text += 'AUTHOR ID: ' + self.authorId + '\n';
        text += 'AUTHOR URL: ' + self.authorUrl + '\n';
        text += 'CONTENT: ' + self.content + '\n';
        text += 'DATE: ' + self.date + '\n';
        text += '-' * 100;
        return text;


if __name__ == '__main__':
    profile = BlogProfile();
    profile.title = 'title';
    profile.url = 'url';
    print str(profile);
